//
//  LRJFoodTableViewCell.m
//  BreadTravel
//
//  Created by 李润嘉 on 15/1/3.
//  Copyright © 2015年 李润嘉. All rights reserved.
//

#import "LRJFoodTableViewCell.h"

@implementation LRJFoodTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createsSubView];
    }
    return self;
}
- (void)createsSubView
{
    //最底层图片
    self.photoImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, WIDTH - 20, WIDTH - 180)];
    self.photoImage.backgroundColor = [UIColor colorWithRed:0.772 green:0.803 blue:1.000 alpha:1.000];
    //改成圆角
    self.photoImage.layer.cornerRadius = 20;
    //masksToBounds防止子元素溢出父视图
    self.photoImage.layer.masksToBounds = YES;
    [self.contentView addSubview:self.photoImage];
    
    
    //图片上的灰色
    UIImageView *grayView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.photoImage.frame.size.width, self.photoImage.frame.size.height)];
    grayView.backgroundColor = [UIColor blackColor];
    grayView.image = [grayView.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    grayView.alpha = 0.3;
    grayView.layer.cornerRadius = 20;
    grayView.layer.masksToBounds = YES;
    [self.photoImage addSubview:grayView];

    
    
    //图片上的标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.photoImage.frame.size.height / 2 - 5, self.photoImage.frame.size.width, 30)];


    [self.contentView addSubview:self.titleLabel];
    
    
    //喜欢背景
    UIImageView *likeImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.photoImage.frame.size.width - 50, 15, 40, 40)];
    likeImage.backgroundColor = [UIColor blackColor];
    likeImage.alpha = 0.6;
    likeImage.layer.cornerRadius = 5;
    likeImage.layer.masksToBounds = YES;
    [self.contentView addSubview:likeImage];
    
    
    //喜欢数
    self.likeLabel = [[UILabel alloc] initWithFrame:CGRectMake(likeImage.frame.origin.x , likeImage.frame.origin.y + 25, 40, 10)];
    [self.contentView addSubview:self.likeLabel];
    
    //喜欢图标(❤️)
    UIImageView *zanImage = [[UIImageView alloc] initWithFrame:CGRectMake(likeImage.frame.origin.x + 10, likeImage.frame.origin.y + 5, 20, 20)];
    zanImage.image = [UIImage imageNamed:@"zan.png"];
    [self.contentView addSubview:zanImage];
    
    

    
}


- (void)setFoodModel:(LRJFoodModel *)foodModel
{
  
    
    self.titleLabel.text = [NSString stringWithFormat:@"- · %@ · -", foodModel.title];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    
    self.likeLabel.text = foodModel.likes;
    self.likeLabel.font = [UIFont systemFontOfSize:10];
    self.likeLabel.textColor = [UIColor whiteColor];
    self.likeLabel.textAlignment = NSTextAlignmentCenter;
    
    //裁掉边框自适应
    self.photoImage.contentMode = UIViewContentModeScaleAspectFill;
    self.photoImage.clipsToBounds = YES;
    [self.photoImage sd_setImageWithURL:[NSURL URLWithString:foodModel.pic] placeholderImage:IMAGE];
    

    
       
}
//重写搜索关键字的setter方法
- (void)setKeyWord:(NSString *)keyWord
{
  
    //设置标签文字
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.titleLabel.text];
    //设置标签文字属性
    NSRange range = [self.titleLabel.text rangeOfString:keyWord];
    //设置标签文字的属性
    [attributedString setAttributes:
     @{NSForegroundColorAttributeName : [UIColor colorWithRed:1.000 green:0.592 blue:0.711 alpha:1.000],
       NSFontAttributeName : [UIFont systemFontOfSize:25]}
                            range : range];
    //把显示的字替换
    self.titleLabel.attributedText = attributedString;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
